from xenmgr.xm.opts import *
-opts = Opts(use="""[options]
+gopts = Opts(use="""[options]
Create a domain.
""")
-opts.opt('help', short='h',
+gopts.opt('help', short='h',
fn=set_value, default=0,
use="Print this help.")
-opts.opt('quiet', short='q',
+gopts.opt('quiet', short='q',
fn=set_true, default=0,
use="Quiet.")
-opts.opt('path', val='PATH',
+gopts.opt('path', val='PATH',
fn=set_value, default='.:/etc/xc',
use="Search path for default scripts.")
-opts.opt('defaults', short='f', val='FILE',
+gopts.opt('defaults', short='f', val='FILE',
fn=set_value, default='xmdefaults',
use="Use the given default script.")
-opts.opt('config', short='F', val='FILE',
+gopts.opt('config', short='F', val='FILE',
fn=set_value, default=None,
use='Domain configuration to use.')
(k, v) = string.split(d, '=')
opt.opts.setvar(k, v)
-opts.opt('define', short='D', val='VAR=VAL',
+gopts.opt('define', short='D', val='VAR=VAL',
fn=set_var, default=None,
use="""Set variables before loading defaults, e.g. '-D vmid=3;ip=1.2.3.4'
to set vmid and ip.""")
-opts.opt('dryrun', short='n',
+gopts.opt('dryrun', short='n',
fn=set_true, default=0,
use="Dry run - print the config but don't create the domain.")
-opts.opt('console', short='c',
+gopts.opt('console', short='c',
fn=set_true, default=0,
use="Connect to console after domain is created.")
-opts.opt('kernel', short='k', val='FILE',
+gopts.opt('kernel', short='k', val='FILE',
+ fn=set_value, default=None,
use="Path to kernel image.")
-opts.opt('ramdisk', short='r', val='FILE',
+gopts.opt('ramdisk', short='r', val='FILE',
fn=set_value, default='',
use="Path to ramdisk.")
-opts.opt('builder', short='b', val='FUNCTION',
+gopts.opt('builder', short='b', val='FUNCTION',
fn=set_value, default='linux',
use="Function to use to build the domain.")
-opts.opt('memory', short='m', val='MEMORY',
+gopts.opt('memory', short='m', val='MEMORY',
fn=set_value, default=128,
use="Domain memory in MB.")
-opts.opt('disk', short='d', val='phy:DEV,VDEV,MODE',
+gopts.opt('disk', short='d', val='phy:DEV,VDEV,MODE',
fn=append_value, default=[],
use="""Add a disk device to a domain. The physical device is DEV, which
is exported to the domain as VDEV. The disk is read-only if MODE is r,
read-write if mode is 'w'.""")
-opts.opt('pci', val='BUS,DEV,FUNC',
+gopts.opt('pci', val='BUS,DEV,FUNC',
fn=append_value, default=[],
- use="""Add a PCI device to a domain.""")
+ use="""Add a PCI device to a domain, using given params (in hex).""")
-opts.opt('ipaddr', short='i', val="IPADDR",
+gopts.opt('ipaddr', short='i', val="IPADDR",
fn=append_value, default=[],
use="Add an IP address to the domain.")
-opts.opt('mac', short='M', val="MAC",
+gopts.opt('mac', short='M', val="MAC",
fn=append_value, default=[],
use="""Add a network interface with the given mac address to the domain.
More than one interface may be specified. Interfaces with unspecified MAC addresses
are allocated a random address.""")
-opts.opt('nics', val="N",
+gopts.opt('nics', val="N",
fn=set_int, default=1,
use="Set the number of network interfaces.")
-opts.opt('vnet', val='VNET',
+gopts.opt('vnet', val='VNET',
fn=append_value, default=[],
use="""Define the vnets for the network interfaces.
More than one vnet may be given, they are used in order.
""")
-opts.opt('root', short='R', val='DEVICE',
+gopts.opt('root', short='R', val='DEVICE',
fn=set_value, default='',
use="""Set the root= parameter on the kernel command line.
Use a device, e.g. /dev/sda1, or /dev/nfs for NFS root.""")
-opts.opt('extra', short='E', val="ARGS",
+gopts.opt('extra', short='E', val="ARGS",
fn=set_value, default='',
use="Set extra arguments to append to the kernel command line.")
-opts.opt('ip', short='I', val='IPADDR',
+gopts.opt('ip', short='I', val='IPADDR',
fn=set_value, default='',
use="Set the kernel IP interface address.")
-opts.opt('gateway', val="IPADDR",
+gopts.opt('gateway', val="IPADDR",
fn=set_value, default='',
use="Set kernel IP gateway.")
-opts.opt('netmask', val="MASK",
+gopts.opt('netmask', val="MASK",
fn=set_value, default = '',
use="Set kernel IP netmask.")
-opts.opt('hostname', val="NAME",
+gopts.opt('hostname', val="NAME",
fn=set_value, default='',
use="Set kernel IP hostname.")
-opts.opt('interface', val="INTF",
+gopts.opt('interface', val="INTF",
fn=set_value, default="eth0",
use="Set the kernel IP interface name.")
-opts.opt('dhcp', val="off|dhcp",
+gopts.opt('dhcp', val="off|dhcp",
fn=set_value, default='off',
use="Set kernel dhcp option.")
-opts.opt('nfs_server', val="IPADDR",
+gopts.opt('nfs_server', val="IPADDR",
fn=set_value, default=None,
use="Set the address of the NFS server for NFS root.")
-opts.opt('nfs_root', val="PATH",
+gopts.opt('nfs_root', val="PATH",
fn=set_value, default=None,
use="Set the path of the root NFS directory.")
config_image.append(['ip', cmdline_ip])
if opts.root:
cmdline_root = strip('root=', opts.root)
- config_image.append(['root', opts.root])
+ config_image.append(['root', cmdline_root])
if opts.extra:
config_image.append(['args', opts.extra])
config.append(['image', config_image ])
d = v.split(',')
if len(d) != 3:
opts.err('Invalid pci specifier: ' + v)
- pci.append(d)
+ # Components are in hex: add hex specifier.
+ hexd = map(lambda v: '0x'+v, d)
+ pci.append(hexd)
opts.pci = pci
def preprocess_ip(opts):
opts.extra = nfs + ' ' + opts.extra
def preprocess(opts):
+ if not opts.kernel:
+ opts.err("No kernel specified")
preprocess_disk(opts)
preprocess_pci(opts)
preprocess_ip(opts)
return (dom, console_port)
def main(argv):
+ opts = gopts
args = opts.parse(argv)
if opts.config:
pass
opts.load_defaults()
if opts.help:
opts.usage()
+ return
preprocess(opts)
config = make_config(opts)
if opts.dryrun:
#!/usr/bin/python
-import string
import sys
+from xenmgr import PrettyPrint
from xenmgr import sxp
from xenmgr.XendClient import server
from xenmgr.xm import create, shutdown
def help(self, meth, args):
name = meth[3:]
f = getattr(self, meth)
- print "%s\t%s" % (name, f.__doc__ or '')
+ print "%-14s %s" % (name, f.__doc__ or '')
def xm_help(self, help, args):
"""Print help."""
print args[0], "FILE"
print "\nRestore a domain from FILE."
if len(args) < 2: self.err("%s: Missing file" % args[0])
- server.xend_domain_restore(dom, None, filename)
+ filename = args[1]
+ server.xend_domain_restore(None, filename)
- def xm_ls(self, help, args):
+ def xm_domains(self, help, args):
"""List domains."""
- if help: self.help('xm_' + args[0]); return
+ if help: self.help('xm_' + args[0], args); return
doms = server.xend_domains()
print 'Dom Name Mem(MB) CPU State Time(s)'
for dom in doms:
d['cpu_time'] = float(sxp.child_value(info, 'cpu_time', '0'))
print ("%(dom)-4d %(name)-16s %(mem)4d %(cpu)3d %(state)5s %(cpu_time)10.2f" % d)
+ def xm_domain(self, help, args):
+ """Get information about a domain."""
+ if help:
+ print args[0], 'DOM'
+ print '\nGet information about domain DOM.'
+ return
+ if len(args) < 2: self.err("%s: Missing domain" % args[0])
+ dom = args[1]
+ info = server.xend_domain(dom)
+ PrettyPrint.prettyprint(info)
+ print
+
def xm_halt(self, help, args):
"""Terminate a domain immediately."""
if help:
"""Shutdown a domain."""
shutdown.main(args)
- def xm_stop(self, help, args):
- """Stop execution of a domain."""
+ def xm_pause(self, help, args):
+ """Pause execution of a domain."""
if help:
print args[0], 'DOM'
print '\nStop execution of domain DOM.'
dom = args[1]
server.xend_domain_stop(dom)
- def xm_start(self, help, args):
- """Start execution of a domain."""
+ def xm_unpause(self, help, args):
+ """Unpause a paused domain."""
if help:
print args[0], 'DOM'
- print '\nStart execution of domain DOM.'
+ print '\nUnpause execution of domain DOM.'
return
if len(args) < 2: self.err("%s: Missing domain" % args[0])
dom = args[1]
v = map(int, args[1:3])
server.xend_domain_pincpu(*v)
- def xm_vif_stats(self, help, args):
- """Get stats for a virtual interface."""
- if help:
- print args[0], 'DOM VIF'
- print '\nGet stats for interface VIF on domain DOM.'
- return
- if len(args) != 3: self.err("%s: Invalid argument(s)" % args[0])
- v = map(int, args[1:3])
- print server.xend_domain_vif_stats(*v)
-
- def xm_vif_rate(self, help, args):
- """Set or get vif rate params."""
- if help:
- print args[0], "DOM VIF [BYTES USECS]"
- print '\nSet or get rate controls for interface VIF on domain DOM.'
- return
- n = len(args)
- if n == 3:
- v = map(int, args[1:n])
- print server.xend_domain_vif_scheduler_get(*v)
- elif n == 5:
- v = map(int, args[1:n])
- server.xend_domain_vif_scheduler_set(*v)
- else:
- self.err("%s: Invalid argument(s)" % args[0])
+## def xm_vif_stats(self, help, args):
+## """Get stats for a virtual interface."""
+## if help:
+## print args[0], 'DOM VIF'
+## print '\nGet stats for interface VIF on domain DOM.'
+## return
+## if len(args) != 3: self.err("%s: Invalid argument(s)" % args[0])
+## v = map(int, args[1:3])
+## print server.xend_domain_vif_stats(*v)
+
+## def xm_vif_rate(self, help, args):
+## """Set or get vif rate params."""
+## if help:
+## print args[0], "DOM VIF [BYTES USECS]"
+## print '\nSet or get rate controls for interface VIF on domain DOM.'
+## return
+## n = len(args)
+## if n == 3:
+## v = map(int, args[1:n])
+## print server.xend_domain_vif_scheduler_get(*v)
+## elif n == 5:
+## v = map(int, args[1:n])
+## server.xend_domain_vif_scheduler_set(*v)
+## else:
+## self.err("%s: Invalid argument(s)" % args[0])
def xm_bvt(self, help, args):
"""Set BVT scheduler parameters."""
print "\nSet round robin scheduler slice."
return
if len(args) != 2: self.err("%s: Invalid argument(s)" % args[0])
- slice = int(args[1])
- server.xend_node_rrobin_set(slice)
+ rrslice = int(args[1])
+ server.xend_node_rrobin_set(rrslice)
def xm_info(self, help, args):
"""Get information about the xen host."""
- if help: self.help('xm_info'); return
+ if help: self.help('xm_' + args[0], args); return
info = server.xend_node()
for x in info[1:]:
print "%-23s:" % x[0], x[1]
+ def xm_consoles(self, help, args):
+ """Get information about domain consoles."""
+ if help: self.help('xm_' + args[0], args); return
+ l = server.xend_consoles()
+ print "Dom Port Id"
+ for x in l:
+ info = server.xend_console(x)
+ d = {}
+ d['dom'] = sxp.child(info, 'dst', ['dst', '?', '?'])[1]
+ d['port'] = sxp.child_value(info, 'port', '?')
+ d['id'] = sxp.child_value(info, 'id', '?')
+ print "%(dom)3s %(port)4s %(id)3s" % d
+
def xm_console(self, help, args):
"""Open a console to a domain."""
if help: